package br.moneymonitor.activity;

import java.util.ArrayList;
import java.util.Calendar;

import android.app.ListActivity;
import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import br.moneymonitor.adapters.AppointmentAdapter;
import br.moneymonitor.beans.Appointment;

public class AppointmentActivity extends ListActivity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.appointment_list);
		ArrayList<Appointment> list = new ArrayList<Appointment>();
		Appointment d = new Appointment("Roupa do Natal", "A", "Eu", 10, 0);
		Calendar c = Calendar.getInstance();
		
		c.set(Calendar.YEAR, 2011);
		c.set(Calendar.DAY_OF_MONTH, 20);
		c.set(Calendar.MONTH, Calendar.APRIL);
		d.setDiasVencimento((int)getDiasParaVencer(c));		
		d.setValor(new Double(100));
		list.add(d);
		
		Appointment d1 = new Appointment("Sushi no hokaido", "A", "Mae", 3, 0);
		c.set(Calendar.YEAR, 2011);
		c.set(Calendar.MONTH, Calendar.APRIL);
		c.set(Calendar.DAY_OF_MONTH, 10);
		d1.setDiasVencimento((int)getDiasParaVencer(c));
		d1.setValor(new Double(100));
		list.add(d1);
		
		Appointment d2 = new Appointment("Sandalia na Fort Couto", "A", "Kelly", 5, 0);
		c.set(Calendar.YEAR, 2011);
		c.set(Calendar.DAY_OF_MONTH, 10);
		c.set(Calendar.MONTH, Calendar.MAY);
		d2.setDiasVencimento((int)getDiasParaVencer(c));
		d2.setValor(new Double(100));
		list.add(d2);
		
		setListAdapter(new AppointmentAdapter(this, list));
		System.out.println("Terminou sem erros...");
	};
	
	private long getDiasParaVencer(Calendar dataVencimento){
		Calendar agora = Calendar.getInstance();
		agora.set(Calendar.HOUR, 0);
		agora.set(Calendar.MINUTE, 0);
		agora.set(Calendar.SECOND, 0);
		System.out.println("***agora = "+agora.getTime() + "----dataVencimento="+dataVencimento.getTime());
		long diferenca = dataVencimento.getTimeInMillis() - agora.getTimeInMillis();
		long tempoDia = 1000 * 60 * 60 * 24;
		return (diferenca / tempoDia); 
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		Toast.makeText(this, "Position" + position, Toast.LENGTH_LONG).show();
	}
}
